﻿Imports System.Data.SqlClient

Public Class Index
    Inherits System.Web.UI.Page
    Dim objrd As SqlDataReader = Nothing
    Dim sSQL As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim objdt As New GetData
        Dim ps As New PreparedStatement("select * from Category where lang_flag='en' order by category_name")
        Dim strErr As String = ""
        '  ps.addParameter("id", 123)
        Dim conn As SqlConnection = objdt.getConn()


        objrd = objdt.dr(ps, strErr, conn, objrd)
        Dim strCat As String = ""
        Dim strCol As String = ""
        Dim strmbl As String = ""
        Dim strnl As String = ""
        strCat = ""
        If Not IsNothing(objrd) Then
            While (objrd.Read())
                strCat &= "<li><a href=""productslist.aspx?cId=" & objrd.Item("category_id") & """>" & objrd.Item("category_name") & "</a></li>"
            End While
            categorylist.InnerHtml = strCat

            ps.strSql = "select * from Columns where lang_flag='en' order by Column_Name"

            objrd = objdt.dr(ps, strErr, conn, objrd)


            While (objrd.Read())
                strCol &= "<li><a href=""column_default.aspx?aid=" & objrd.Item("Column_ID") & """>" & objrd.Item("Column_Name") & "</a></li>"
            End While
            columnlist.InnerHtml = strCol

            ps.strSql = "select top 10 * from Column_New where Column_ID in (select Column_ID from Columns where  lang_flag='en')  order by create_date desc"

            objrd = objdt.dr(ps, strErr, conn, objrd)
            While (objrd.Read())
                strnl &= "<li><a href=""columnlist.aspx?newsId=" & objrd.Item("New_ID") & "&aid=" & objrd.Item("Column_ID") & """>" & objrd.Item("title") & "</a></li>"
            End While
            clist.InnerHtml = strnl


            ps.strSql = "select top 10 * from purchase where lang_flag='en' order by create_Date desc"

            objrd = objdt.dr(ps, strErr, conn, objrd)
            While (objrd.Read())
                strmbl &= "<li><a href=""#"">" & objrd.Item("title").ToString & "</a></li>"
            End While
            mlist.InnerHtml = strmbl


            sSQL = "select top 6 *  from  product_info where active=1 and lang_flag='en' order by create_date desc"
            ps.strSql = sSQL

            objrd = objdt.dr(ps, strErr, conn, objrd)
            pDiv.InnerHtml = "<table width=""100%"">"
            Dim photoPath As String
            While (objrd.Read())
                Dim i As Integer
                i = 0
                If objrd("photo_path").ToString = "" Then
                    photoPath = "/pic/nopic180.gif"
                Else
                    photoPath = objrd("photo_path").ToString
                End If

                pDiv.InnerHtml += "<tr>"
                pDiv.InnerHtml += "<td width=""33%"" height=""160px"" valign=""top"" align=""center"">"
                pDiv.InnerHtml += "<div><a href=""productdetail.aspx?productId=" & objrd.Item("product_id") & """><img width=""180px"" height=""130px"" src=""" & photoPath & """/></a></div>"
                pDiv.InnerHtml += "<div style=""line-height:25px;"">" & objrd("Product_name").ToString & "</div> </td>"
                For i = 0 To 1
                    If objrd.Read() Then
                        If objrd("photo_path").ToString = "" Then
                            photoPath = "/pic/nopic180.gif"
                        Else
                            photoPath = objrd("photo_path").ToString
                        End If
                        pDiv.InnerHtml += "<td width=""33%"" height=""160px"" valign=""top"" align=""center"">"
                        pDiv.InnerHtml += "<div><a href=""productdetail.aspx?productId=" & objrd.Item("product_id") & """><img width=""180px"" height=""130px"" src=""" & photoPath & """/></a></div>"
                        pDiv.InnerHtml += "<div style=""line-height:25px;"">" & objrd("Product_name").ToString & "</div> </td>"
                    Else
                        Exit For
                    End If
                Next
                pDiv.InnerHtml += "</tr>"
            End While
            objdt.closeConn(conn)

            pDiv.InnerHtml += "</table>"
        End If

    End Sub

    Protected Sub search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles search.Click
        Dim searchType, country, name As String
        searchType = Request("searchType")
        country = Request("country")
        name = Request("name")
        If (searchType.ToLower.Equals("product")) Then
            Response.Redirect("searchproductlist.aspx?country=" & country & "&name=" & name)
        ElseIf (searchType.ToLower.Equals("company")) Then
            Response.Redirect("searchcompanylist.aspx?country=" & country & "&name=" & name)
        End If
    End Sub
End Class